package com.fulihui.weixinsdk.request.customer;

import com.alibaba.fastjson.JSON;
import com.fulihui.weixinsdk.http.HttpMethodEnum;
import com.fulihui.weixinsdk.model.Material;
import com.fulihui.weixinsdk.request.WeixinRequest;
import com.fulihui.weixinsdk.result.customer.CustomerImgMsgResult;
import com.fulihui.weixinsdk.result.customer.CustomerMPNewsMsgResult;
import com.google.gson.Gson;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.TreeMap;

/**
 * 发送图片消息
 *
 * @author wang_wx
 * @date 2018-07-12
 */
@Data
public class CustomerImgMsgRequest extends WeixinRequest<CustomerImgMsgResult> {


    /**
     * token
     */
    private transient String access_token;

    /**
     *接收消息的OPENID
     */
    private String touser;

    /**
     * 消息类型
     */
    private String msgtype="image";

    /**
     * 图文消息集合 不要超过8条 否则将无响应
     */
    private Material image;

    //endregion

    @Override
    public Map<String, String> urlParam() {
        Map<String, String> param = new TreeMap<>();
        if (StringUtils.isNotBlank(access_token)) {
            param.put("access_token", access_token);
        }
        return param;
    }

    @Override
    protected void childParam() {

    }

    @Override
    public String service() {
        return "https://api.weixin.qq.com/cgi-bin/message/custom/send";
    }

    @Override
    public String urlEndStr() {
        return null;
    }

    @Override
    public CustomerImgMsgResult parseResult(String respStr) {
        return new Gson().fromJson(respStr, CustomerImgMsgResult.class);
    }

    @Override
    public HttpMethodEnum httpMethod() {
        return HttpMethodEnum.POST;
    }

    @Override
    public String requestData() {
        return JSON.toJSONString(this);
    }
}
